#include "guiterm.hpp"

const int MessageSegment::ErrorMessage = 0;
const int MessageSegment::InfoMessage = 1;

MessageSegment::MessageSegment(Session *session, string message, int messageType)
	:ViewSegment(session)
{
	QSizePolicy sizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
	setSizePolicy(sizePolicy);
	
	layout = new QHBoxLayout();
	layout->setSpacing(0);
	layout->setContentsMargins(5,0,0,0);
	setLayout(layout);
	
	// If the last char in the message is a newline, strip it, so that there's
	// no blank line at the end.
	if(message[message.size()-1]=='\n')
		message = message.substr(0, message.size()-1);
	
	label = new QLabel(message.c_str());
	if(messageType == ErrorMessage)
		label->setPalette(*PaletteManager::errorMessage());
	else
		label->setPalette(*PaletteManager::statusMessage());
	layout->addWidget(label);
}

MessageSegment::~MessageSegment()
{
	delete label;
	delete layout;
}

